﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using FXnaGis;

using FXnaInfrastructure;

using System.Drawing;





namespace NSCore
{


    /// <summary>
    /// 用于表示所有的结果数据
    /// 这里我们尝试将结果保存分开
    /// </summary>
    [Serializable]
    public class NSResult
    {

        public NSResult()
        {


            this._contourLayer.IsSelectable = false;

 
        }


        #region 事件

        [field:NonSerialized]
        public event EventHandler ResultChanged;


        #endregion




        ResultState _resultState;

        /// <summary>
        /// 存储计算状态
        /// 
        /// </summary>
        public ResultState ResultState
        {
            get { return _resultState; }
            set { _resultState = value; }
        }






        /// <summary>
        /// 主网格计算数据
        /// </summary>


        FEntityCollection _mainGrids = new FEntityCollection();


        /// <summary>
        /// 用于封装主网格的数据集合
        /// </summary>
        public FEntityCollection MainGrids
        {
            get { return _mainGrids; }
           
        }



        FEntityCollection _scatterPoints=new FEntityCollection ();



        //等值线是UI相关的数据，这里的设计有点奇怪






        FVectorLayer _contourLayer = new FVectorLayer(NSCoreNames.ContourLayer);
        /// <summary>
        /// 用于绘制，存储等值线相关的功能，
        /// 用于表现，多层次，多网格
        /// 
        /// </summary>
        public FVectorLayer ContourLayer
        {
            get { return _contourLayer; }

        }



        #region 函数


        /// <summary>
        /// 保持同步的数据结构
        /// </summary>
        /// <param name="gridLayer"></param>
        public void ResetMainGridResult(NSData data)
        {

            //重新读取，主城的网格数据


            this._mainGrids.Clear();


            FVectorLayer gridLayer = data.GridLayer;

            foreach (FShape item in gridLayer.Shapes.Values)
            {

                GridReceptor gr = item as GridReceptor;


                TimedGridResult tgr = new TimedGridResult(data.TimeDivides,gr);

                this._mainGrids.Add(tgr);




                
            }







 
        }


        public void TestReadData()
        {


            if (this.ResultChanged!=null)
            {
                this.ResultChanged(this,EventArgs.Empty);

                
            }



            List<FShape> shps = new List<FShape>();


            List<ContourLine> lines = new List<ContourLine>();


            lines.Add(new ContourLine(20, Color.Azure));

            lines.Add(new ContourLine(30,Color.AliceBlue));

            lines.Add(new ContourLine(40, Color.Blue));

            lines.Add(new ContourLine(50, Color.Red));

            lines.Add(new ContourLine(60, Color.Green));


            foreach (TimedGridResult item in this._mainGrids.Entities)
            {
                
                //我们先取第一个

                GridResult gr=  item.Childrens.Values.ToList<GridResult>()[0];


                 FContourShape contour = new FContourShape(item.Id,gr.Grid);

                 contour.Data = gr.ContribueValue;

                 contour.SetContourLines(lines);


                 shps.Add(contour);

                 
                
            }


            //注意这里使用 的reset哦

            this._contourLayer.ResetShapes(shps);





        }



        #endregion

    }
}
